package com.gulimall.order.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.gulimall.order.domain.entity.OrderItem;
import com.gulimall.order.domain.entity.RefundInfo;
import com.gulimall.order.mapper.OrderItemMapper;
import com.gulimall.order.service.IOrderItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * <p>
 * 订单项信息 服务实现类
 * </p>
 *
 * @author 坤哥
 * @since 2025-08-25
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    @RabbitListener(queues = {"hello-java-queue"})
    public void testReceiveMessage(Message message,
                                   RefundInfo refundInfo){
        byte[] body = message.getBody();
        String json = new String(body, StandardCharsets.UTF_8);
        RefundInfo refundInfo1 = JSONObject.parseObject(json, RefundInfo.class);
        System.out.println(refundInfo1);
        System.out.println("接收到消息" + message + "==》消息类型为 " + message.getClass());
        System.out.println("实体类为 = " + refundInfo);
    }
}
